package com.cjbdi.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.cjbdi.entity.Subscribe;

@Repository
public interface SubscribeRepository extends JpaRepository<Subscribe, Long> {
	@Query(value = "select * from subscribe as a where id = :id", nativeQuery = true)
    List<Subscribe> findById(int id);
	
	@Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "delete from subscribe where id=:id",nativeQuery = true)//原生SQL
    Integer delete(@Param("id")int id);
	
	@Query(value = "select * from subscribe where case when :sfunction!=''then function_name like '%'||:sfunction||'%' else 1=1 end" , nativeQuery = true)
    Page<Subscribe> getPageByParam(@Param("sfunction") String sfunction,Pageable pageable);
}
